CLS
OPEN "lodira.in" FOR INPUT AS #1
OPEN "lodira.out" FOR OUTPUT AS #2

INPUT #1, m, t, u, f, d
flg = 1
FOR i = 1 TO t
  INPUT #1, c$
  IF flg = 1 THEN
    IF m < 0 THEN
      PRINT #2, LTRIM$(STR$(i - 2))
      flg = 0
    END IF

    IF c$ = "f" THEN
      m = m - 2 * f
    ELSE
      m = m - u - d
    END IF
  END IF
NEXT i

CLOSE #1, #2
END

